package com.situ.shoplook.dubbo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.shoplook.common.model.Cart;
import com.situ.shoplook.common.model.CartTemp;
import com.situ.shoplook.common.model.Product;
import com.situ.shoplook.common.service.CartService;
import com.situ.shoplook.common.util.PaginateInfo;
import com.situ.shoplook.dubbo.dao.CartDao;
import com.situ.shoplook.dubbo.dao.ProductDao;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author:yzy
 * @date:2024/9/5
 */
@Service
@DubboService
@CacheConfig(cacheNames = "c.s.s.d.s.impl.CartServiceImpl")

public class CartServiceImpl implements CartService {
    private CartDao cartDao;
    @Autowired
    public void setCartDao(CartDao cartDao) {
        this.cartDao = cartDao;
    }
    @Override
    public Map<String, Object> findAll(PaginateInfo pi) {
        try (Page<Cart> __ = PageHelper.startPage(pi.getPageNo(), pi.getPageSize())) {
            List<Cart> carts = this.cartDao.findAll();
            PageInfo<Cart> pageInfo = new PageInfo<>(carts);
            pi.setPageNo(pageInfo.getPageNum());
            pi.setPageSize(pageInfo.getPageSize());
            pi.setTotal((int)pageInfo.getTotal());
            carts = List.copyOf(carts);
            System.out.println(carts);
            return Map.of( "data", carts, "pi", pi);
        }
    }
}
